//
//  TelBookViewModel.swift
//  telephoneBook
//
//  Created by cyptt on 2023/6/18.
//

import UIKit
import CHSimpleUI
class CHPDFViewModel: CHBaseVModel  {

    
    override init(successBlock: ViewModelMoreDataSuccessBlock? = nil, failBlock: ViewModelSFailBlock? = nil) {
        super.init(successBlock: successBlock,failBlock: failBlock)
    }
    
    func refreshData(isMoreData: Bool = false,files:[String]?) {
        //MARK: 一般这里进行网络请求
        
        if isMoreData == false{
            self.datas.removeAll()
        }

        if files?.count != nil{
            for i in 0..<files!.count {
                let model:CHPDFModel? =  CHPDFModel()
                model?.dataType = .filePathString
                model?.fileUrl = files?[i]
                if model != nil {
                    self.datas.append(model!)
                }
               
            }
        }
      
       
        if self.successMoreDataBlock != nil {
            self.successMoreDataBlock!(self.datas,isMoreData)
        }
    }
      
    func refreshData(isMoreData: Bool = false,urls:[URL]?) {
        //MARK: 一般这里进行网络请求
        
        if isMoreData == false{
            self.datas.removeAll()
        }

        if urls?.count != nil{
            for i in 0..<urls!.count {
                let model:CHPDFModel? =  CHPDFModel()
         
                model?.dataType = .fileURL
                model?.url = urls?[i]
                if model != nil {
                    self.datas.append(model!)
                }
               
            }
        }
      
       
        if self.successMoreDataBlock != nil {
            self.successMoreDataBlock!(self.datas,isMoreData)
        }
    }
    func refreshData(isMoreData: Bool = false,datas:[Data]?) {
        //MARK: 一般这里进行网络请求
        
        if isMoreData == false{
            self.datas.removeAll()
        }

        if datas?.count != nil{
            for i in 0..<datas!.count {
                let model:CHPDFModel? =  CHPDFModel()
                model?.dataType = .data
                model?.data = datas?[i]
                if model != nil {
                    self.datas.append(model!)
                }
               
            }
        }
      
       
        if self.successMoreDataBlock != nil {
            self.successMoreDataBlock!(self.datas,isMoreData)
        }
    }
}


